import './assets/main.css'

import { createApp } from 'vue'
import { createPinia } from 'pinia'
import ElementPlus from 'element-plus'
import 'element-plus/dist/index.css'
import * as ElementPlusIconsVue from '@element-plus/icons-vue'
import { createI18n } from 'vue-i18n'

import App from './App.vue'
import router from './router'

// 国际化配置
const messages = {
  en: {
    nav: {
      home: 'Home',
      editor: 'Editor',
      templates: 'Templates'
    },
    home: {
      title: 'Professional Online Collage Maker',
      subtitle: 'Simple drag & drop to create stunning collages. 31+ professional templates with rich layout combinations for 1-9 images, make your photos more creative.',
      privacyNotice: '100% Privacy Protection - All image processing is done locally in your browser, no uploads to any server',
      getStarted: 'Start Creating Collage',
      whyChoose: 'Why Choose CollageCraft?',
      features: {
        templates: '30+ Collage Templates',
        templatesDesc: 'From basic layouts to creative designs, meet all collage needs',
        privacy: 'Complete Privacy Protection',
        privacyDesc: 'All processing done locally, your photos never leave your device',
        easy: 'Simple & Intuitive',
        easyDesc: 'Drag and drop interface, no learning curve required',
        export: 'High Quality Export',
        exportDesc: 'Export high-resolution images for print and sharing',
        feature1Title: '30+ Collage Templates',
        feature1Desc: 'From 1 to 25 images per template, covering all your collage needs with perfect layouts',
        feature2Title: 'Simple & Easy',
        feature2Desc: 'Drag to upload images, click to select templates, one-click to generate collages',
        feature3Title: 'High Quality Export',
        feature3Desc: 'Support PNG format export, maintain original image quality',
        feature4Title: 'Completely Free',
        feature4Desc: 'No registration required, no watermarks, completely free to use'
      },
      stats: {
        templates: 'Templates',
        users: 'Users',
        downloads: 'Downloads',
        rating: 'Rating',
        stat1Label: 'Template Count',
        stat1Suffix: '',
        stat2Label: 'Supported Formats',
        stat2Suffix: 'types',
        stat3Label: 'Max Resolution',
        stat3Suffix: 'px',
        stat4Label: 'User Satisfaction',
        stat4Suffix: '%'
      },
      cta: {
        title: 'Ready to Create Your Collage?',
        subtitle: 'High quality, easy to use, start creating now',
        button: 'Start Creating Now'
      },
      templatesTitle: 'Rich Template Library',
      templatesSubtitle: '24 carefully designed collage templates to meet different scenario needs',
      footer: {
        title: 'CollageCraft',
        description: 'Professional online collage making tool, making your photos more creative.',
        product: 'Product',
        templateLibrary: 'Template Library',
        editor: 'Editor',
        support: 'Support',
        userGuide: 'User Guide',
        feedback: 'Feedback',
        copyright: '© 2025 CollageCraft by Solming. Contact: solming001[at]gmail.com'
      },
      templateNames: {
        single: 'Single',
        leftRight: 'Left-Right',
        topBottom: 'Top-Bottom',
        leftBig: 'Left Big',
        topBig: 'Top Big',
        threeColumn: '3 Columns',
        threeRow: '3 Rows',
        leftBigRightTwo: 'Left Big + 2 Right',
        topBigBottomTwo: 'Top Big + 2 Bottom',
        threeMosaic: '3 Mosaic',
        fourGrid: '2×2 Grid',
        fourColumn: '4 Columns',
        fourRow: '4 Rows',
        leftOneRightThree: 'Left 1 + Right 3',
        fourMix: '4 Mix',
        fiveColumn: '5 Columns',
        fiveRow: '5 Rows',
        centerFour: 'Center + 4 Corners',
        fiveMix: '5 Mix',
        sixGrid: '2×3 Grid',
        sixColumn: '6 Columns',
        twoThreeMix: '2+4 Mix',
        sixMix: '6 Mix',
        sevenMix1: '7 Mix Style 1',
        sevenMix2: '7 Mix Style 2',
        eightGrid: '2×4 Grid',
        eightColumn: '8 Columns',
        eightMix: '8 Mix',
        nineGrid: '3×3 Grid',
        nineColumn: '9 Columns',
        nineMix: '9 Mix'
      }
    },
    mode: {
      simple: {
        tooltip: 'Simple mode: Easy to use with essential features',
        description: 'Perfect for quick collages with minimal learning curve'
      },
      professional: {
        tooltip: 'Professional mode: Full-featured editing experience',
        description: 'Advanced tools for creative professionals'
      }
    },
    templates: {
      title: 'Template Library',
      search: 'Search templates...',
      category: 'Category',
      ratio: 'Ratio',
      style: 'Style',
      all: 'All',
      basic: 'Basic Templates',
      social: 'Social Media',
      creative: 'Creative Templates',
      minimal: 'Minimal',
      modern: 'Modern',
      artistic: 'Artistic',
      vintage: 'Vintage',
      useTemplate: 'Use Template',
      downloads: 'downloads',
      noResults: 'No matching templates found',
      adjustFilters: 'Try adjusting filter conditions or search keywords'
    },
    editor: {
      title: 'Collage Editor',
      back: 'Back',
      clear: 'Clear',
      autoFill: 'Auto Fill',
      save: 'Save',
      download: 'Download Image',
      tips: '💡 Drag images to move, scroll wheel to zoom',
      addImage: 'Click to add image',
      dragMove: 'Drag to move | Scroll to zoom',
      reset: 'Reset',
      delete: 'Delete',
      imageLibrary: 'Image Library',
      dragUpload: 'Drag images here or click to upload',
      supportedFormats: 'Supports JPG, PNG, GIF formats'
    }
  },
  zh: {
    nav: {
      home: '首页',
      editor: '编辑器',
      templates: '模板库'
    },
    home: {
      title: '专业的在线拼图制作工具',
      subtitle: '简单拖拽，轻松制作精美拼图。31+种专业模板，为1-9张图片提供丰富的布局组合，让您的照片更有创意。',
      privacyNotice: '100% 隐私保护 - 所有图片处理均在您的浏览器本地完成，不会上传到任何服务器',
      getStarted: '开始制作拼图',
      whyChoose: '为什么选择拼图工坊？',
      features: {
        templates: '30+ 拼图模板',
        templatesDesc: '从基础布局到创意设计，满足各种拼图需求',
        privacy: '完全隐私保护',
        privacyDesc: '所有处理均在本地完成，您的照片不会离开设备',
        easy: '简单直观',
        easyDesc: '拖拽式界面，无需学习成本',
        export: '高质量导出',
        exportDesc: '导出高分辨率图片，适合打印和分享',
        feature1Title: '30+种拼图模板',
        feature1Desc: '从1张到25张图片的模板，完美布局满足您的所有拼图需求',
        feature2Title: '简单易用',
        feature2Desc: '拖拽上传图片，点击选择模板，一键生成拼图',
        feature3Title: '高质量导出',
        feature3Desc: '支持PNG格式导出，保持图片原始质量',
        feature4Title: '完全免费',
        feature4Desc: '无需注册，无水印，完全免费使用'
      },
      stats: {
        templates: '模板',
        users: '用户',
        downloads: '下载',
        rating: '评分',
        stat1Label: '模板数量',
        stat1Suffix: '个',
        stat2Label: '支持格式',
        stat2Suffix: '种',
        stat3Label: '最大尺寸',
        stat3Suffix: 'px',
        stat4Label: '用户满意度',
        stat4Suffix: '%'
      },
      cta: {
        title: '准备开始制作您的拼图了吗？',
        subtitle: '高质量，易使用，立即开始创作',
        button: '立即开始制作'
      },
      templatesTitle: '丰富的模板库',
      templatesSubtitle: '24种精心设计的拼图模板，满足不同场景需求',
      footer: {
        title: '拼图工坊',
        description: '专业的在线拼图制作工具，让您的照片更有创意。',
        product: '产品',
        templateLibrary: '模板库',
        editor: '编辑器',
        support: '支持',
        userGuide: '使用指南',
        feedback: '意见反馈',
        copyright: '© 2025 拼图工坊 by Solming. 联系邮箱: solming001[at]gmail.com'
      },
      templateNames: {
        single: '单图',
        leftRight: '左右分割',
        topBottom: '上下分割',
        leftBig: '左大右小',
        topBig: '上大下小',
        threeColumn: '三列布局',
        threeRow: '三行布局',
        leftBigRightTwo: '左大右二',
        topBigBottomTwo: '上大下二',
        threeMosaic: '三图拼接',
        fourGrid: '四宫格',
        fourColumn: '四列布局',
        fourRow: '四行布局',
        leftOneRightThree: '左一右三',
        fourMix: '四图混合',
        fiveColumn: '五列布局',
        fiveRow: '五行布局',
        centerFour: '中心四角',
        fiveMix: '五图混合',
        sixGrid: '六宫格',
        sixColumn: '六列布局',
        twoThreeMix: '二四混合',
        sixMix: '六图混合',
        sevenMix1: '七图组合1',
        sevenMix2: '七图组合2',
        eightGrid: '八宫格',
        eightColumn: '八列布局',
        eightMix: '八图混合',
        nineGrid: '九宫格',
        nineColumn: '九列布局',
        nineMix: '九图混合'
      }
    },
    mode: {
      simple: {
        tooltip: '简单模式：易于使用，包含基本功能',
        description: '适合快速制作拼图，学习成本低'
      },
      professional: {
        tooltip: '专业模式：功能完整的编辑体验',
        description: '为创意专业人士提供高级工具'
      }
    },
    templates: {
      title: '模板库',
      search: '搜索模板...',
      category: '分类',
      ratio: '比例',
      style: '风格',
      all: '全部',
      basic: '基础模板',
      social: '社交媒体',
      creative: '创意模板',
      minimal: '简约',
      modern: '现代',
      artistic: '艺术',
      vintage: '复古',
      useTemplate: '使用模板',
      downloads: '下载',
      noResults: '没有找到匹配的模板',
      adjustFilters: '尝试调整筛选条件或搜索关键词'
    },
    editor: {
      title: '拼图编辑器',
      back: '返回',
      clear: '清空',
      autoFill: '自动填充',
      save: '保存',
      download: '下载图片',
      tips: '💡 拖拽图片移动位置，滚轮缩放大小',
      addImage: '点击添加图片',
      dragMove: '拖拽移动 | 滚轮缩放',
      reset: '重置',
      delete: '删除',
      imageLibrary: '图片库',
      dragUpload: '拖拽图片到此处或点击上传',
      supportedFormats: '支持 JPG、PNG、GIF 格式'
    }
  }
}

// 检测用户地理位置来确定语言
function detectLocale(): string {
  try {
    // 首先检查localStorage中保存的语言设置
    const savedLanguage = localStorage.getItem('language')
    if (savedLanguage && (savedLanguage === 'zh' || savedLanguage === 'en')) {
      return savedLanguage
    }

    // 检查浏览器语言
    if (navigator.language.startsWith('zh')) {
      return 'zh'
    }
  } catch (error) {
    console.log('Language detection failed, using default')
  }

  // 默认使用英文
  return 'en'
}

// 初始化语言设置
const initialLocale = detectLocale()

const i18n = createI18n({
  legacy: false,
  locale: initialLocale,
  fallbackLocale: 'en',
  messages
})

const app = createApp(App)

// 注册Element Plus图标
for (const [key, component] of Object.entries(ElementPlusIconsVue)) {
  app.component(key, component)
}

app.use(createPinia())
app.use(router)
app.use(ElementPlus)
app.use(i18n)

app.mount('#app')
